package com.xq.tmall.controller.fore;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Author : JiangLinHan
 * Date : 2019/9/6
 * Time : 15:56
 * 用于redis测试
 **/
@RestController
@RequestMapping(value="/redis", produces = "application/json; charset=UTF-8")
public class RedisDemoController {

    @Autowired
    private RedisTemplate redisTemplate;

    @RequestMapping( "/set")
    public String setUserName(String name) {
        redisTemplate.opsForValue().set("1", name);
        return "succees";
    }

    @RequestMapping( "/get")
    public String getUserName(String key) {
        return  redisTemplate.opsForValue().get(key).toString()==null?"查询的key不存在":redisTemplate.opsForValue().get(key).toString();
    }


}
